package com.example.yls.demoa;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {
    private Wuziqi wuziqi;
    private AlertDialog.Builder builder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        wuziqi = findViewById(R.id.wuziqi);

        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        wuziqi = findViewById(R.id.wuziqi);
        builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("游戏结束");
        builder.setNegativeButton("退出", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int which) {
                MainActivity.this.finish();
            }
        });
        builder.setPositiveButton("再来一局", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int which) {
                wuziqi.restart();
            }
        });
        wuziqi.setOnGameListener(new Wuziqi.onGameListener() {
            @Override
            public void onGameOver(int i) {
                String str="";
                if(i == Wuziqi.WHITE_WIN){
                    str="白棋胜利！";
                }else if(i == Wuziqi.BLACK_WIN){
                    str="黑棋胜利！";
                }
                builder.setMessage(str);
                builder.setCancelable(false);
                AlertDialog dialog = builder.create();
                Window dialogWindow = dialog.getWindow();
                WindowManager.LayoutParams params = new
                        WindowManager.LayoutParams();
                params.x = 0;
                params.y=Wuziqi.getUnder();
                dialogWindow.setAttributes(params);
                dialog.setCanceledOnTouchOutside(false);
                dialog.show();
            }
        });
    }
}
